<template>
  <div class="callback-container">
    <el-card class="callback-box">
      <template #header>
        <div class="callback-header">
          <el-icon><Loading /></el-icon>
          <span>正在处理登录请求...</span>
        </div>
      </template>
      <p>请稍候，正在验证您的身份信息</p>
    </el-card>
  </div>
</template>

<script setup>
import { onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useUserStore } from '@/store/modules/user'
import { ElMessage } from 'element-plus'
import { Loading } from '@element-plus/icons-vue'

const route = useRoute()
const router = useRouter()
const userStore = useUserStore()

onMounted(async () => {
  try {
    // 从URL中获取授权码
    const code = route.query.code
    if (!code) {
      throw new Error('授权失败')
    }

    // 处理第三方登录
    // 这里需要根据实际情况调用后端API
    // await userStore.loginByThirdParty({ code })
    
    ElMessage.success('登录成功')
    router.push('/')
  } catch (error) {
    ElMessage.error(error.message || '登录失败')
    router.push('/login')
  }
})
</script>

<style scoped>
.callback-container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f5f7fa;
}

.callback-box {
  width: 400px;
}

.callback-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #409EFF;
}

.callback-header .el-icon {
  animation: rotating 2s linear infinite;
}

@keyframes rotating {
  from {
    transform: rotate(0);
  }
  to {
    transform: rotate(360deg);
  }
}
</style> 